home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Misc / msql-1.0.6 / src / common / flock.c < prev    next >
C/C++ Source or Header  |  1994-06-29  |  873b  |  53 lines

  1. /*
  2. **    flock.c        - Implementation of flock using SysV fcntl's
  3. **
  4. **    Author    :     David J. Hughes   ( Bambi@Bond.edu.au )
  5. **    Date    :    16-Feb-1994
  6. **    Org    :     Information Technology Services
  7. **            Bond University
  8. **
  9. **    This code is placed in the public domain and can be used for any
  10. **    purposes.  It is supplied "as is" without any implied warranty.
  11. **    etc. etc. etc.
  12. */
  13.  
  14.  
  15. #include <stdio.h>
  16. #include <fcntl.h>
  17.  
  18. #include "config.h"
  19. #include "portability.h"
  20.  
  21. #ifndef HAVE_FLOCK
  22.  
  23. int flock(fd,op)
  24.     int    fd,
  25.         op;
  26. {
  27.     int    res;
  28.     flock_t    arg;
  29.  
  30.     if (LOCK_EX & op)
  31.         arg.l_type = F_WRLCK;
  32.     else if (LOCK_SH & op)
  33.         arg.l_type = F_RDLCK;
  34.     else if (LOCK_UN & op)
  35.         arg.l_type = F_UNLCK;
  36.  
  37.     arg.l_whence = 0;
  38.     arg.l_start = 0;
  39.     arg.l_len = 0;
  40.     
  41.     if (op & LOCK_NB)
  42.         res = fcntl(fd,F_SETLK, &arg);
  43.     else
  44.         res = fcntl(fd,F_SETLKW, &arg);
  45.  
  46.     if (res == -1)
  47.         return(-1);
  48.     else
  49.         return(0);
  50. }
  51.  
  52. #endif
  53.